package com.meiyou.service.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.meiyou.mapper.AppSettingMapper;
import com.meiyou.mapper.MeiyouSettingMapper;
import com.meiyou.service.AppSettingService;
import com.meiyou.utils.LoginSession;
import com.meiyou.utils.ShareCodeUtil;

@Service
public class AppSettingServiceImpl implements AppSettingService{
    
	@Autowired
	AppSettingMapper appsetting;
	@Autowired
	MeiyouSettingMapper settingMaper;
	
	
	/**
	 * 获取置顶费
	 */
	public String selZhiDingfei() {
		// TODO Auto-generated method stub
		String zdf = appsetting.selZhiDingFei();
		return zdf;
	}
	
	/**
	 * 更新置顶费
	 */
	public boolean updZhiDingfei(String num,HttpServletRequest req) {
		// TODO Auto-generated method stub
		if(managerLogin(req)) {
			if(appsetting.altZhiDingFei(num)==1) {
				return true;
			}
			return false;
		}
		return  false;
	}
	
	/**
	 * 获取安卓下载地址
	 */
	public String selUrlForAndroid() {
		// TODO Auto-generated method stub
		String url = appsetting.selAndroidUrl();
		return url;
	}

	/**
	 * 更新安卓下载地址
	 */
	public boolean updUrlForAndroid(String url,HttpServletRequest req) {
		if(managerLogin(req)) {
			// TODO Auto-generated method stub
			if(appsetting.updAndroidUrl(url)==1) {
				return true;
			}
			else{
				return false;
			}
			
		}
		return false;
		
	}
	
    /**
         * 判断管理员是否登录
     */
	public boolean managerLogin(HttpServletRequest req) {
		if(req.getSession().getAttribute("manager")!=null) {		
				return true;
		}
		else {
			return false;
		}
	}
    
	/**
	 * 获取苹果下载地址
	 */
	public String selUrlForIphone() {
		// TODO Auto-generated method stub
		String url = appsetting.selIphoneUrl();
		return url;
	}
    /**
     * 更新苹果下载地址
     */
	public boolean updUrlForIphone(String url, HttpServletRequest req) {
		// TODO Auto-generated method stub
		if(managerLogin(req)) {
			if(appsetting.updIphoneUrl(url)==1) {
				return true;
			}
			return false;
		}
		return false;
	}
    
	

    /**
     * 获取诚意金
     */
	public String selChenYiJin() {
		// TODO Auto-generated method stub
		String cyj = appsetting.selChenYiJin();
		return cyj;
	}
    /**
     * 更新诚意金
     */
	public boolean updChenYiJin(String num, HttpServletRequest req) {
		// TODO Auto-generated method stub
		if(managerLogin(req)) {
			if(appsetting.altChenYiJin(num)==1) {
				return true;
			}
		}
		return false;
	}
    /**
     * 获取官方电话
     */
	public String selTelPhone() {
		// TODO Auto-generated method stub
		String phone = appsetting.selTelPhone();
		return phone;
	}
    /**
     * 更新官方电话
     */
	public boolean updTelPhone(String phone, HttpServletRequest req) {
		// TODO Auto-generated method stub
		if(managerLogin(req)) {
			if(appsetting.updTelPhone(phone)==1) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 	获取平台发布金
	 */
	public String selFaBuJin() {
		// TODO Auto-generated method stub
		String value = appsetting.selFaBuJin();
		
		return value;
	}

	/**
	 * 更新平台发布金
	 */
	public boolean updFaBuJin(String num, HttpServletRequest req) {
		// TODO Auto-generated method stub
		if(managerLogin(req)) {
			if(appsetting.updFaBuJin(num)==1) {
				return true;
			}
		}
		return false;
	}
   
	/**
	 * 获取提现手续费
	 */
	public String selTiXian() {
		// TODO Auto-generated method stub
		String num = appsetting.selTiXian();
		return num;
	}
    /**
     * 更新提现手续费   
     */
	public boolean updTiXian(String num, HttpServletRequest req) {
		// TODO Auto-generated method stub
		if(managerLogin(req)) {
			if(appsetting.updTiXian(num)==1) {
				return true;
			}
		}
		return false;
	}
   
	/**
	 * 用户分享业务
	 */
	public boolean insShare(String acount,HttpServletRequest req) {
		// TODO Auto-generated method stub
		String s_time = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());//获取当前时间
		String s_code = ShareCodeUtil.toSerialCode(new Random().nextInt());//邀请码生成
		String s_state = "未填写";
		if(LoginSession.userLogin(req)) {
			
			return false;
		}
		return false;
	}

	public String selChongzhiBili() {
		// TODO Auto-generated method stub
		
		return settingMaper.selChongzhiBili();
	}
}
